package com.dqhl.business.view;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.PopupWindow;

import com.dqhl.business.R;
import com.dqhl.business.util.ScreenUtils;

/**
 * Created by guanluocang on 2016/11/7.
 */
public class ShopSettingPopwindow extends PopupWindow{

    private Activity context;

    public ShopSettingPopwindow(Activity context, View.OnClickListener itemOnClick) {
        super(context);
        this.context = context;
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.layout_shopsettingpopwindow, null);
        Button btn_food = (Button) view.findViewById(R.id.btn_food);
        Button btn_cloths = (Button) view.findViewById(R.id.btn_cloths);
        Button btn_hospital = (Button) view.findViewById(R.id.btn_hospital);
        Button btn_shopping = (Button) view.findViewById(R.id.btn_shopping);
        Button btn_electric = (Button) view.findViewById(R.id.btn_electric);
        Button btn_cancel = (Button) view.findViewById(R.id.btn_cancel);

        btn_cancel.setOnClickListener(itemOnClick);
        btn_food.setOnClickListener(itemOnClick);
        btn_cloths.setOnClickListener(itemOnClick);
        btn_hospital.setOnClickListener(itemOnClick);
        btn_shopping.setOnClickListener(itemOnClick);
        btn_electric.setOnClickListener(itemOnClick);

        int width = (int) (ScreenUtils.getScreenWidth(context) * 0.9);
        setWidth(width);
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
        setBackgroundDrawable(new ColorDrawable(0));
        setFocusable(true);
        setOutsideTouchable(true);
        setContentView(view);
        update();
    }

    public void backgroundAlpha(float bgAlpha) {
        WindowManager.LayoutParams lp = context.getWindow().getAttributes();
        lp.alpha = bgAlpha; //0.0-1.0+
        context.getWindow().setAttributes(lp);
    }
}
